package com.hxd.otc.module.coin_deal.presenter;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.coin_deal.bean.ChooseCoinBean;
import com.hxd.otc.module.coin_deal.bean.CoinDealRequestBean;
import com.hxd.otc.module.coin_deal.bean.CoinDealResultBean;
import com.hxd.otc.module.coin_deal.bean.CoinRequestTransBean;
import com.hxd.otc.module.coin_deal.contract.CoinDealContract;
import com.hxd.otc.module.coin_deal.model.CoinDealModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.LogUtils;
import com.hxd.otc.utils.ResourceUtil;

import java.util.List;

/**
 * 包  名 :  com.hxd.otc.module.coin_deal.presenter
 * 类  名 :  CoinDealPresenter
 * 作  者 :  胡庆岭
 * 时  间 :  2018/7/9 11:52
 * 描  述 :  ${币币交易Presenter}
 */
public class CoinDealPresenter extends BasePresenter<CoinDealContract.View> implements CoinDealContract.Presenter {

    private final CoinDealModel mModel;

    public CoinDealPresenter(CoinDealContract.View view) {
        super(view);
        mModel = CoinDealModel.getInstance();
    }

    @Override
    public void start() {

    }

    @Override
    public void loadData(CoinDealRequestBean bean) {
        mModel.loadData(bean, new BaseObserver<CoinDealResultBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull CoinDealResultBean bean) {
                mView.resultData(bean.list);
                mView.onShowNoMore();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
                mView.onShowNoMore();
            }
        }, mView.<BaseBean<CoinDealResultBean>>bindAutoDispose());
    }

    @Override
    public void deleteCoinDeal(String id) {
        mModel.deleteEntryOrders(id, new BaseObserver<String>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.showToast(ResourceUtil.getString(R.string.delete_succeed));
                mView.deleteCoinDealSucceed();
                LogUtils.w("deleteEntryOrders--" + s);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public void getLastPrice(String bbTransPair) {
        mModel.lastPrice(bbTransPair, new BaseObserver() {
            @Override
            public void onNext(String msg, Object object) {
                if (object == null || TextUtils.isEmpty(object.toString())) {
                    mView.resultLastPrice("");
                } else {
                    mView.resultLastPrice(String.valueOf(object));
                }

            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

            }


        }, mView.<BaseBean>bindAutoDispose());
    }

    @Override
    public void getCoinTypePrice() {
        mModel.getCoinTypePrice(new BaseObserver<List<ChooseCoinBean>>() {
            @Override
            public void onNext(String msg, List<ChooseCoinBean> hashMapHashMap) {
                mView.getCoinTypePrice(hashMapHashMap);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

                mView.showToast(errMessage);
            }


        }, mView.<BaseBean<List<ChooseCoinBean>>>bindAutoDispose());
    }

    @Override
    public void transCoinDeal(CoinRequestTransBean bean) {
        mModel.transCoinDeal(bean, new BaseObserver() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
                mView.showToast(o.toString());
                mView.transCoinDealSucceed();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }


        }, mView.<BaseBean>bindAutoDispose());

    }

    @Override
    public void doShowNoMore() {
        mView.onShowNoMore();
    }


}
